#! coding:utf-8
#!/usr/bin/env python
"""
    @author jay.han
    kvm constant
"""


class StorageMap(object):
    ISCSI = 'iscsi'
    NETFS = 'netfs'
    LOCAL = 'dir'
    FC = 'fc'

    _types = {
        ISCSI:'iSCSI Target',
        NETFS:'Network File System',
        LOCAL : 'local file disk',
        FC:'Fibre Channel'
    }


class StorageStatus(object):
    # virStoragePoolState
    POOL_INACTIVE = 0
    POOL_BUILDING = 1
    POOL_RUNNING = 2
    POOL_DEGRADED = 3
    POOL_INACCESSIBLE = 4
    POOL_ERROR = -1

    _STORAGE_MAP = {
        POOL_INACTIVE: 'inactive',
        POOL_BUILDING: 'building',
        POOL_RUNNING: 'running',
        POOL_DEGRADED: 'degraded',
        POOL_INACCESSIBLE: 'inaccessible',
        POOL_ERROR:'error'

    }
    @classmethod
    def name(cls,code):
        return StorageStatus._STORAGE_MAP[code]


class TaskAction(object):
    CLIENT = 'client'
    VM = 'VM'
    NETWORK = 'network'
    STORAGE = 'storage'

    CREATE_VM = 'create_vm'
    CLONE_VM = 'clone vm'
    START_VM = 'start_vm'
    SHUTDOWN_VM = 'shutdown_vm'
    REBOOT_VM = 'reboot_vm'
    FORCE_SHUTDOWN_VM = 'force_shutdown_vm'
    DESTORY_VM = 'destory_vm'
    UPDATE_VM = 'update_vm'
    SNAPSHOT_VM='snapshot_vm'
    RESTORE_VM = 'restore vm'

    ADD_STORAGE = 'add storage'
    REMOVE_STORAGE = 'remove storage'

    CREATE_NETWORK ="add network"
    UPDATE_NETWORK ="update network"
    DELETE_NETWORK = "remove network"
    PAUSE_VM = "pause vm"
    UNPAUSE_VM = "unpause vm"
    SAVE_TEMPLATE = "save template"
    HIBERNATE_VM = 'hibernate vm'
    UPDATE_DISK = 'update disk'
    DELETE_DISK = 'delete disk'
    UPDATE_CDROM = 'update cdrom'
    ADD_DISK = 'add disk'
    DELETE_SNAP = "delete snapshot"

    MIGRATE_VM = "migrate vm"
    LOGIN_VM = 'login vm'

KVM_DRIVER_COW='qcow2'
KVM_DRIVER_RAW='raw'
KVM_SPICE = 'spice'
KVM_VNC='vnc'

AGENT_INSTANCE_PATH = '/opt/cvirt/instances'
GUEST_AGENT_PATH = '/opt/cvirt/channels'

def getGuestAgentPath(instance_name):
    return GUEST_AGENT_PATH + '/'+ instance_name + '.com.morningcloud.guest'

""" template """
VOLUME_TEMPLATE=u"vol-%08.f"
SNAP_TEMPLATE=u"snap-%08.f"
INSTANCE_TEMPLATE=u"i-%08.f"
IMAGE_TEMPLATE =u'img-%08.f'
""" End """

NAT = 0
ISOLATE = 1
BRIDGE = 2
VLAN = 3


TO_MB = float(1073741824)
BUFFER_SIZE = 4096

def isWindows(os_type):
    return os_type.startswith("Windows")

def isLinux(os_type):
    return (os_type.startswith('ArchLinux')
            or os_type.startswith('Debian')
            or os_type.startswith('Fedora')
            or os_type.startswith('FreeBSD')
            or os_type.startswith('Gentoo')
            or os_type.startswith('Linux')
            or os_type.startswith('OpenBSD')
            or os_type.startswith('OpenSUSE')
            or os_type.startswith('OpenSolaris')
            or os_type.startswith('RedHat')
            or os_type.startswith('Solaris')
            or os_type.startswith('Ubuntu')
    )

def whichOS(os_type):
    if(isWindows(os_type)):
        return 'windows'
    elif(isLinux(os_type)):
        return 'linux'
    else:
        return 'others'
OSTYPES = {'ArchLinux': 'Arch Linux',
           'ArchLinux_64': 'Arch Linux (64 bit)',
           'DOS': 'DOS',
           'Debian': 'Debian',
           'Debian_64': 'Debian (64 bit)',
           'Fedora': 'Fedora',
           'Fedora_64': 'Fedora (64 bit)',
           'FreeBSD': 'FreeBSD',
           'FreeBSD_64': 'FreeBSD (64 bit)',
           'Gentoo': 'Gentoo',
           'Gentoo_64': 'Gentoo (64 bit)',
           'JRockitVE': 'JRockitVE',
           'L4': 'L4',
           'Linux': 'Other Linux',
           'Linux22': 'Linux 2.2',
           'Linux24': 'Linux 2.4',
           'Linux24_64': 'Linux 2.4 (64 bit)',
           'Linux26': 'Linux 2.6',
           'Linux26_64': 'Linux 2.6 (64 bit)',
           'MacOS': 'Mac OS X Server',
           'MacOS_64': 'Mac OS X Server (64 bit)',
           'Mandriva': 'Mandriva',
           'Mandriva_64': 'Mandriva (64 bit)',
           'NetBSD': 'NetBSD',
           'NetBSD_64': 'NetBSD (64 bit)',
           'Netware': 'Netware',
           'OS2': 'Other OS/2',
           'OS2Warp3': 'OS/2 Warp 3',
           'OS2Warp4': 'OS/2 Warp 4',
           'OS2Warp45': 'OS/2 Warp 4.5',
           'OS2eCS': 'eComStation',
           'OpenBSD': 'OpenBSD',
           'OpenBSD_64': 'OpenBSD (64 bit)',
           'OpenSUSE': 'openSUSE',
           'OpenSUSE_64': 'openSUSE (64 bit)',
           'OpenSolaris': 'Oracle Solaris 10 10/09 and later',
           'OpenSolaris_64': 'Oracle Solaris 10 10/09 and later (64 bit)',
           'Oracle': 'Oracle',
           'Oracle_64': 'Oracle (64 bit)',
           'Other': 'Other/Unknown',
           'QNX': 'QNX',
           'RedHat': 'Red Hat',
           'RedHat_64': 'Red Hat (64 bit)',
           'Solaris': 'Oracle Solaris 10 5/09 and earlier',
           'Solaris_64': 'Oracle Solaris 10 5/09 and earlier (64 bit)',
           'Turbolinux': 'Turbolinux (64 bit)',
           'Ubuntu': 'Ubuntu',
           'Ubuntu_64': 'Ubuntu (64 bit)',
           'Windows2000': 'Windows 2000',
           'Windows2003': 'Windows 2003',
           'Windows2003_64': 'Windows 2003 (64 bit)',
           'Windows2008': 'Windows 2008',
           'Windows2008_64': 'Windows 2008 (64 bit)',
           'Windows31': 'Windows 3.1',
           'Windows7': 'Windows 7',
           'Windows7_64': 'Windows 7 (64 bit)',
           'Windows8': 'Windows 8',
           'Windows8_64': 'Windows 8 (64 bit)',
           'Windows95': 'Windows 95',
           'Windows98': 'Windows 98',
           'WindowsMe': 'Windows Me',
           'WindowsNT': 'Other Windows',
           'WindowsNT4': 'Windows NT 4',
           'WindowsVista': 'Windows Vista',
           'WindowsVista_64': 'Windows Vista (64 bit)',
           'WindowsXP': 'Windows XP',
           'WindowsXP_64': 'Windows XP (64 bit)',
           'Xandros': 'Xandros',
           'Xandros_64': 'Xandros (64 bit)'}




